﻿@model AexoManager.Models.RegistroTiemposViewModel


@{
    Layout = null;
}

@functions {
    object getHtmlAttributes(bool ReadOnly, string CssClass, string PlaceHolder)
    {
        if (ReadOnly)
        {
            return new { @class = CssClass, @readonly = "readonly" };
        }
        return new { @class = CssClass, @placeholder = PlaceHolder };
    }
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Registro de tiempos</title>

    <script type='text/javascript' src='~/Content/assets/js/jquery-1.10.2.min.js'></script>
    <script type='text/javascript' src='~/Content/assets/js/jqueryui-1.10.3.min.js'></script>
    <script type='text/javascript' src='~/Content/assets/js/bootstrap.min.js'></script>

    <link rel="stylesheet" href="~/Content/assets/css/styles.min.css" />
    <link rel="stylesheet" href="~/Content/assets/css/styleCustom.css" />
    <link rel='stylesheet' type='text/css' href='~/Content/assets/js/jqueryui.css' />
    <link rel='stylesheet' type='text/css' href='~/Content/assets/plugins/pines-notify/jquery.pnotify.default.css' />

    @Scripts.Render("~/bundles/jqueryval")

    <script language="javascript" type="text/javascript">
        $(function () {
            //$("#Inicio").datepicker({ dateFormat: "dd/mm/yy" });
            $("#fechaFin").datepicker({ dateFormat: "dd/mm/yy" });

            jQuery.validator.addMethod(
                 'date',
                 function (value, element, params) {
                     if (this.optional(element)) return true;
                     var ok = true;
                     try {
                         $.datepicker.parseDate('dd/mm/yy', value);
                     } catch (err) {
                         ok = false;
                     }
                     return ok;
                 },
                  'Must enter date in dd-mm-yyyy format.'
              );

            $("#IdUsuario").change(function () {
                $("#CodigoPieza").focus();
            });

            $("#CodigoPieza").keypress(function (event) {
                if (event.which == 13) {
                    $("#Cantidad").focus();
                }
            });

            $("#Cantidad").keypress(function (event) {
                if (event.which == 13) {
                    $("#IdProceso").focus();
                }
            });

            $("#IdProceso").change(function () {
                $("#btnSubmit").focus();
            });

            $("#btnReanudar").click(function () {
                $("#formRegistro").attr("action", "@Url.Content("~/")Produccion/Reanudar");
                $("#formRegistro").submit();
            });

            $("#btnPausar").click(function () {
                $("#formRegistro").attr("action", "@Url.Content("~/")Produccion/Pausar");
                $("#formRegistro").submit();
            });
            
            $("#btnSubmit").click(function () {
                $("#formRegistro").submit();
            });
            
        });

    </script>

</head>
<body class="focusedform">

    <div class="centradovertical">
        <img src="~/Content/assets/img/Logo-Aexo.png" alt="Logo" class="brand" />
        @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors != null && ViewData.ModelState[k].Errors.Count() > 0))
        {
            <div class="alert alert-dismissable alert-danger">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                @Html.ValidationSummary("Error!")
            </div>
        }
        <div class="panel panelCentrado panel-primary">
            @using (Html.BeginForm("Registro", "Produccion", FormMethod.Post, new { @id = "formRegistro", @class = "form-horizontal" }))
            {
                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)
                
                <div class="panel-body">
                    <h4 class="text-center" style="margin-bottom: 25px;">Registro de tiempos</h4>

                    <div class="form-group">
                        <div class="col-sm-12">
                            @Html.DropDownListFor(model => model.IdEmpleado, new SelectList(ViewBag.Usuarios, "IdEmpleado", "NombreCompleto"), "Seleccionar Empleado", @getHtmlAttributes(Model.ReadOnly, "form-control", ""))
                            @Html.ValidationMessageFor(model => model.IdEmpleado)
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-12">
                            @Html.DropDownListFor(model => model.CodigoPieza, new SelectList(ViewBag.Partes, "Codigo", "Descripcion"), "Seleccionar Parte", @getHtmlAttributes(Model.ReadOnly, "form-control", ""))
                            @Html.ValidationMessageFor(model => model.CodigoPieza)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-12">
                            @Html.TextBoxFor(model => model.Cantidad, @getHtmlAttributes(Model.ReadOnly, "form-control", "Cantidad"))
                            @Html.ValidationMessageFor(model => model.Cantidad)
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-12">
                            @Html.DropDownListFor(model => model.IdProceso, new SelectList(ViewBag.procesos, "IdProceso", "Descripcion"), "Seleccionar Proceso", @getHtmlAttributes(Model.ReadOnly, "form-control", ""))
                            @Html.ValidationMessageFor(model => model.IdProceso)
                        </div>
                    </div>
                    @{
                if (Model != null && Model.Inicio != null)
                {
                    <div class="form-group">
                        <div class="col-sm-12">
                            @Html.TextBoxFor(model => model.Inicio, @getHtmlAttributes(Model.ReadOnly, "form-control", "Fecha Inicio"))
                        </div>
                    </div>
                }
                    }
                </div>

                <div class="panel-footer">
                    @if (Model != null && Model.Inicio != null)
                    {
                        <div class="pull-left">
                            <input type="button" id="btnPausar" class="btn-warning btn" value="Pausar">
                        </div>

                    }
                    @if (Model != null && Model.IdComienzo != 0)
                    {
                        @Html.HiddenFor(model => model.IdComienzo);
                        <div class="pull-left">
                            <input type="button" id="btnReanudar" class="btn-warning btn" value="Reanudar">
                        </div>
                    }

                    @if (Model != null && Model.IdComienzo == 0)
                    {
                        <div class="pull-right">
                            <input type="button" id="btnSubmit" class="btn-primary btn" value="@ViewBag.AccionBoton">
                        </div>
                    }
                </div>
            }

        </div>
    </div>
</body>

</html>